;; MODO DE EMPLEO `dzen2-mensaje-string'
;; (shell-command
;;  (dzen2-mensaje-string "3s" "recarga"))

(defun dzen2-mensaje-string (msg_tiempo msg)
  (interactive)
  (setq
   alerta-finish-string
   (format
    "( %s && %s && %s ) & ( sleep 1s && %s )"
    "command -v pacman &> /dev/null"
    "pacman -Ss sndio | grep -q ins"
    "doas service sndiod restart &> /dev/null"
    (format
     "mpv --loop=inf %s &> /dev/null"
     "~/.emacs.d/p/ln/sound.computersound.opus")))
  (setq dzen2-limpiar-string
	(format
	 "%s &> /dev/null && ( %s )"
	 "pgrep dzen2"
	 "pgrep dzen2 | xargs kill"))
  (setq
   width_screen
   (substring
    (shell-command-to-string
     (format
      "echo -n $(xrandr | %s | %s)"
      "awk '/ connected/ { print $4}'"
      "cut -d'x' -f 1"))))
  (setq
   height_screen
   (substring
    (shell-command-to-string
     (format
      "echo -n $(xrandr | %s | %s | %s)"
      "awk '/ connected/ { print $4}'"
      "cut -d'x' -f 2"
      "cut -d'+' -f 1"))))
  (setq
   start_dzen
   (format
    "( echo '%s %s' | dzen2 -p -w %s -h %s %s )"
    msg_tiempo
    msg
    width_screen
    height_screen
    "-fg 'yellow' -bg 'black' -fn 'Hack-35'"))
  (setq
   end_dzen
   (format
    "( echo 'fin %s %s' | dzen2 -p -w %s -h %s %s || %s )"
    msg
    msg_tiempo
    width_screen
    height_screen
    "-fg 'yellow' -bg 'black' -fn 'Hack-35'"
    "killall mpv"))
  (princ
   (format
    "( %s ) && ( %s ) && %s || %s "
    (format
     "( %s & ( sleep %s && %s )"
     start_dzen    
     msg_tiempo
     dzen2-limpiar-string)
    (format
     "( %s & ( sleep %s && %s ) ) )"
     end_dzen
     msg_tiempo
     alerta-finish-string)
    "killall mpv"
    "killall mpv")))

(defun recargarse
    (tiempo)
  (interactive
   "s¿Por cuanto tiempo se recargará?:")
  (async-shell-command (dzen2-mensaje-string tiempo "recarga")))

(defun bloque-de-tiempo
    (tiempo_de_bloque tiempo_de_recarga)
  (interactive
   "s¿Cuanto dura su bloque?: \n\
s¿Cuanto dura su recarga?: ")
  (async-shell-command
   (format
    "sleep %s && %s"
    tiempo_de_bloque
    (dzen2-mensaje-string tiempo_de_recarga "recarga"))))